package demo1229.chenweiqun;


public class BaoziStore extends Thread{
    private Baozi baozi;

    public BaoziStore(Baozi baozi) {
        this.baozi = baozi;
    }

    @Override
    public void run() {
        int count = 0;
        while (true){
            synchronized (baozi){
                if (baozi.isExist()){
                    try {
                        baozi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("做包子");
                if (count%3==1){
                    baozi.setPi("薄皮");
                    baozi.setXian("牛肉汤");
                }else if(count%3==2){
                    baozi.setPi("厚皮");
                    baozi.setXian("青菜");
                }else {
                    baozi.setPi("薄皮");
                    baozi.setXian("豆沙");
                }
                count++;
                baozi.setExist(true);
                baozi.notify();
            }
        }
    }
}
